package com.baihan.angus.app.game.busshow.ui.user.feedback;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.RadioGroup;

import androidx.lifecycle.Observer;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.baihan.angus.app.game.basic.base.BaseActivity;
import com.baihan.angus.app.game.basic.utils.Tooast;
import com.baihan.angus.app.game.busshow.BR;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.busshow.databinding.ActivityFeedbackBinding;
import com.baihan.angus.app.game.common.arouter_path.ArouterAppPath;
import com.baihan.angus.app.game.common.bean.response.FeedbackResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * 意见反馈
 */
@Route(path = ArouterAppPath.FEEDBACK_ACTIVITY)
public class FeedbackActivity extends BaseActivity<ActivityFeedbackBinding, FeedbackVM> {

    private Map<String, Object> mFeedbackRequest = new HashMap<>();

    private int userType = 0;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_feedback;
    }

    @Override
    protected int getViewModelId() {
        return BR.feedbackVM;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

        mVDBinding.titleView.setLeftOnClickListener(view -> finish());

        mVDBinding.rgRole.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (i == R.id.rbPlayer) {
                    userType = 0;
                } else if (i == R.id.rbDM) {
                    userType = 5;
                }
            }
        });

        mVDBinding.tvSubmit.setOnClickListener(view -> {

            String content = mVDBinding.etContent.getText().toString();
            String contract = mVDBinding.etContract.getText().toString();
            if (TextUtils.isEmpty(content)) {
                Tooast.normalInfo("请输入反馈内容");
            } else {
                mFeedbackRequest.put("type", userType);
                mFeedbackRequest.put("content", content);
                mFeedbackRequest.put("contact", contract);
                mViewModel.feedback(mFeedbackRequest);
            }
        });
    }

    @Override
    protected void initObservers() {
        super.initObservers();
        mViewModel.mldFeedback.observe(this, new Observer<FeedbackResponse.Data>() {
            @Override
            public void onChanged(FeedbackResponse.Data data) {
                if (null != data) {
                    Tooast.normalInfo("已反馈");
                    finish();
                }
            }
        });
    }
}